package com.sugar.psych.assessment.module.business.controller.app.usertreeholeclock;

import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import com.sugar.psych.assessment.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.psych.assessment.module.business.controller.admin.usertreeholeclock.vo.UserTreeHoleClockPageReqVO;
import com.sugar.psych.assessment.module.business.controller.admin.usertreeholeclock.vo.UserTreeHoleClockRespVO;
import com.sugar.psych.assessment.module.business.controller.admin.usertreeholeclock.vo.UserTreeHoleClockSaveReqVO;
import com.sugar.psych.assessment.module.business.controller.app.usertreeholeclock.vo.AppUserTreeHoleClockMonthRespVO;
import com.sugar.psych.assessment.module.business.controller.app.usertreeholeclock.vo.AppUserTreeHoleClockSaveReqVO;
import com.sugar.psych.assessment.module.business.dal.dataobject.usertreeholeclock.UserTreeHoleClockDO;
import com.sugar.psych.assessment.module.business.service.usertreeholeclock.UserTreeHoleClockService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.successApp;

@Tag(name = "APP - 树洞打卡")
@RestController
@RequestMapping("/psych/user-tree-hole-clock")
@Validated
public class AppUserTreeHoleClockController {

    @Resource
    private UserTreeHoleClockService userTreeHoleClockService;

    @PostMapping("/create")
    @Operation(summary = "创建树洞打卡")
    public CommonResult<Long> createUserTreeHoleClock(@Valid @RequestBody AppUserTreeHoleClockSaveReqVO createReqVO) {
        return successApp(userTreeHoleClockService.appCreateUserTreeHoleClock(createReqVO, SecurityFrameworkUtils.getLoginUserId()));
    }


    @GetMapping("/get")
    @Operation(summary = "根据日期-获得树洞打卡")
    public CommonResult<List<UserTreeHoleClockRespVO>> getUserTreeHoleClock(@RequestParam("date") String date) {
        return successApp(userTreeHoleClockService.getUserTreeHoleClockByDate(date, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/month")
    @Operation(summary = "获得一个月内哪些天数有打卡数据")
    public CommonResult<List<AppUserTreeHoleClockMonthRespVO>> getOneMonthData(@RequestParam("date") String date) {
        return successApp(userTreeHoleClockService.getOneMonthData(date, SecurityFrameworkUtils.getLoginUserId()));
    }
}